package com.acmedcare.framework.exchange.center.common;

import com.github.pagehelper.PageInfo;
import java.util.List;

public class ConvertUtils {

  public static <T> Page<T> convertPage(List<T> list) {

    PageInfo<T> pageInfo = new PageInfo<>(list);
    Page<T> page = new Page<T>(pageInfo.getPageSize(), pageInfo.getPageNum(),
        (int) pageInfo.getTotal());
    page.setList(list);
    return page;
  }

  public static <Target, Source> Target convertType(Source source, Class<Target> targetClass) {
    java.lang.String str = JacksonHelper.objectToJson(source);
    Target target = JacksonHelper.jsonToObject(str, targetClass);
    return target;
  }

  public static <Target, Source extends List> List<Target> convertToList(Source source,
      Class<Target> targetClass) {
    java.lang.String str = JacksonHelper.objectToJson(source);
    return JacksonHelper.jsonToList(str, targetClass);
  }
}
